//
//  MTSettingCell.m
//  ShiShiBang
//
//  Created by 宋宝强 on 16/9/19.
//  Copyright © 2016年 motianjituan. All rights reserved.
//

#import "MTSettingCell.h"
#import "MTSettingRowItem.h"
#import "MTArrowItem.h"
#import "MTSwitchItem.h"
#import "MTTextItem.h"

@implementation MTSettingCell

/**
 *  快速创建一个cell
 *
 *  @param tableView tableView
 *  @param style     cell类型
 *
 *  @return 创建好的Cell
 */

+ (MTSettingCell *)cellWithTableView:(UITableView *)tableView Style:(UITableViewCellStyle)style{
    static NSString *ID = @"settingCell";
    MTSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[MTSettingCell alloc] initWithStyle:style reuseIdentifier:ID];
    }
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


- (void)setRowItem:(MTSettingRowItem *)rowItem {
    _rowItem = rowItem;
    
    //设置辅助视图
    [self setUpAccessoryView:rowItem];
    
    //设置数据
    [self setUpDataWith:rowItem];
}


/**
 *  设置辅助视图
 */
- (void)setUpAccessoryView:(MTSettingRowItem *)rowItem {
    //判断模型的类型
    if ([rowItem isKindOfClass:[MTArrowItem class]]) {
        //箭头
        self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"setting_icon-an"]];
    }else if([rowItem isKindOfClass:[MTSwitchItem class]]) {
        //开关
        self.accessoryView = [[UISwitch alloc] init];
    }else if([rowItem isKindOfClass:[MTTextItem class]]){
        //文字
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"设置" forState:UIControlStateNormal];
        [btn setTitleColor:MTColor(256, 218, 58) forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];
        btn.titleLabel.font = [UIFont systemFontOfSize:18];
        btn.userInteractionEnabled = NO;
        [btn sizeToFit];
        self.accessoryView = btn;
    }else {
         self.accessoryView = nil;
    }
}
/**
 *  设置数据
 */
- (void)setUpDataWith:(MTSettingRowItem *)rowItem {
    self.textLabel.text = rowItem.title;
    self.imageView.image = rowItem.image;
    self.detailTextLabel.text = rowItem.detailT;
}


@end
